#include "Restaurant.h"
#include <iostream>
#include <string>
using namespace std;

/*These are the functions respnsible for the User Interface part of the code*/
Restaurant R;

void Tester_getGuest(const int guestNumber){
	string setVal;
	if (R.checkGuestExistence(guestNumber)&&R.checkOrderExistence(guestNumber)) { 
	cout<<"What information would you like to get from the order of guest number "<<guestNumber<<"?\nfirst/main/beverage/desert \n\n";
	cin>>setVal;
	if (setVal=="first") { 
	R.getGuest(guestNumber,0);
	}
	else if (setVal=="main") { 
	R.getGuest(guestNumber,1);
	}
	if (setVal=="desert") { 
	R.getGuest(guestNumber,2);
	}
	if (setVal=="beverage") { 
	R.getGuest(guestNumber,3);
	}
	}
	else {
		cout<<"Guest number "<<guestNumber<<" does not have an order or  does not exist  \n\n";
		return;
	}
}
void Tester_removeGuestFeature(const int guestNumber){
	string setVal;
	if (R.checkGuestExistence(guestNumber)&&R.checkOrderExistence(guestNumber)) { 
	cout<<"What information would you like to remove from guest number "<<guestNumber<<"?\nfirst/main/beverage/desert \n\n";
	cin>>setVal;
	if (setVal=="first") { 
		R.setGuest(guestNumber,"",0);
	}
	else if (setVal=="main") { 
		R.setGuest(guestNumber,"",1);
	}
	if (setVal=="desert") { 
		R.setGuest(guestNumber,"",2);
	}
	if (setVal=="beverage") { 
		R.setGuest(guestNumber,"",3);
	}
	}
	else {
		cout<<"Guest number "<<guestNumber<<" does not have an order or does not exist and could not be set \n\n";
		return;
	}
}


void Tester_setGuest(const int guestNumber) { 
	string setVal;
	if (R.checkGuestExistence(guestNumber)&&R.checkOrderExistence(guestNumber)) { 
	cout<<"What would you like to set in the order of  guest number "<<guestNumber<<"?\nfirst/main/beverage/desert \n\n";
	cin>>setVal;
	if (setVal=="first") { 
	cout<<("Please enter first course: \n\n");
	cin>>setVal;
	R.setGuest(guestNumber,setVal,0);
	}
	else if (setVal=="main") { 
	cout<<("Please enter main course: \n\n");
	cin>>setVal;
	R.setGuest(guestNumber,setVal,1);
	}
	if (setVal=="desert") { 
	cout<<("Please enter desert: \n\n");
	cin>>setVal;
	R.setGuest(guestNumber,setVal,2);
	}
	if (setVal=="beverage") { 
	cout<<("Please enter beverage: \n\n");
	cin>>setVal;
	R.setGuest(guestNumber,setVal,3);
	}
	}

	else {
		cout<<"Guest number "<<guestNumber<<" does not have an order or does not exist and could not be set \n\n";
		return;
	}
}

void Tester_removeGuest(const int guestNumber) { 
		R.removeGuest(guestNumber);
}

void Tester_removeOrder(const int guestNumber) { 
	R.removeOrder(guestNumber);
}
void Tester_addOrder(const int guestNumber) { 
	 if (!R.checkGuestExistence(guestNumber)) {
			cout<<"Guest number: "<<guestNumber<< " does not exist"<<endl;
			return;
	 }
	else if (!R.checkOrderExistence(guestNumber)) { 
		cout<<"What would the guest want to eat for first course ?\n";
		string fc;
		cin>>fc;
		string mc;
		cout<<"What would the guest want to eat for main course ?\n";
		cin>>mc;
		string bev;
		cout<<"What would the guest want to drink ?\n";
		cin>>bev;
		string des;
		cout<<"What would the guest want to eat for desert ?\n";
		cin>>des;
		R.addOrder(guestNumber,des,bev,mc,fc);


	}
	else 
		cout<<"Order for guest number: "<<guestNumber<< " is not empty ! please choose the set command or remove his order"<<endl;
}

void Tester_addNewGuest() { 
	string yesNo = "";
	bool ho=false;
	string fc,mc,bev,des;
	cout<<"Guest will be added without ordering anything"<<endl<<"Would you like to set the guest's order now ? yes/no"<<endl;
	cin>>yesNo;
	if (yesNo=="yes") { 
		ho = true;
	cout<<"What would the guest want to eat for first course ?\n";
	cin>>fc;

	cout<<"What would the guest want to eat for main course ?\n";
	cin>>mc;

	cout<<"What would the guest want to drink ?\n";
	cin>>bev;

	cout<<"What would the guest want to eat for desert ?\n";
	cin>>des;
	}
	bool b = (yesNo=="yes" ||yesNo=="no");
	if (b) { 
	R.addGuest(des,mc,fc,bev,ho);
	
	}
	else cout<<"Invalid input"<<endl;
}

int main() { 	

string command = "";
	string setVal;
	cout<< "Hello and welcome to the restaurant guest orders system"<<endl;
	cout<<"To add a new guest type \"add-g\""<<endl;
	cout<<"To add a new order for an existing guest type \"add-o\""<<endl;
	cout<<"To remove a part of a guest order type \"r\""<<endl;
	cout<<"To remove a guest completely from the restaurant type \"remove-g\""<<endl;
	cout<<"To remove a guest order type \"remove-o\""<<endl;
	cout<<"To set information about a guest order type \"set\""<<endl;
	cout<<"To get information about a guest order type \"get\""<<endl;;


	while(true) { 
	int guestNumber = -500;
	cout<< "Please enter your command: \n\n";
	cin>>command;
	
	//add a guest
	if (command=="add-g") {
		Tester_addNewGuest();
	}
	else if (command=="add-o") {
		cout<<("Please enter guest number add an order to: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number"<<endl;
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else Tester_addOrder(guestNumber);
	}
	//set an exisiting guest
	else if (command=="set") {
		cout<<("Please enter guest number to set: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number"<<endl;
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else { 
			Tester_setGuest(guestNumber);
		}
	}
	//remove an existing guest
	else if (command=="remove-g"){
		cout<<("Please enter guest number to remove: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number\n\n";
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else Tester_removeGuest(guestNumber);
		
		
	}
	else if (command=="remove-o"){
		cout<<("Please enter guest number to remove an order from: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number\n\n";
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else Tester_removeOrder(guestNumber);
		
		
	}
	else if (command=="get"){
		cout<<("Please enter guest number to get information about: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number\n\n";
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else Tester_getGuest(guestNumber);
	}
	else if (command=="r"){
		cout<<("Please enter guest number to romove certain information about: \n\n");
		cin>>guestNumber;
		if (guestNumber==-500){
		cerr<<"Invalid guest number\n\n";
		cin.clear();
		std::cin.ignore( 1024, '\n' );
		continue;
		}
		else Tester_removeGuestFeature(guestNumber);
	}
	else if (command=="exit"){
		cout<<"Thank you and goodbye\n\n";
		exit(0);
	}
	else cout<<"Command: "<<command<<" is not a valid command"<<"\n\n";

	}
}





